#include "SpaceEngine.hpp"

#include "GameState.hpp"

// Constructor
SpaceEngine::SpaceEngine()
{
	m_pAppStateManager = 0;
}

// Destructor
SpaceEngine::~SpaceEngine()
{
	delete m_pAppStateManager;
	delete OgreFramework::getSingletonPtr();
}

// Start up the whole application and its state manager. Then set an itnial state.
void SpaceEngine::startEngine()
{
	// Start up a new OgreFramework. Remember, it is a singleton, so it doesn't 
	// really have a variable. There is only one of these things at a time.
	new OgreFramework();

	// If Ogre fails to initialise, then just end the program here.
	if (!OgreFramework::getSingletonPtr()->initOgre("Advanced Ogre", 0, 0))
		return;

	// Create a new AppStateManager
	m_pAppStateManager = new AppStateManager();

	// Create the states that we already programmed.
	GameState::create(m_pAppStateManager, "GameState");

	// Start the AppStateManager with the inital state of MenuState.
	m_pAppStateManager->start(m_pAppStateManager->findByName("GameState"));
}